package com.wangmeng.book.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * User: 王猛
 * Date: 13-7-25
 */
public class SpringContextManager implements ApplicationContextAware {
    private static ApplicationContext context;
    private static AtomicBoolean isInit = new AtomicBoolean(false);

    public static ApplicationContext getContext() {
        if (isInit.get()) {
            return context;
        }
        return null;
    }

    public void setApplicationContext(ApplicationContext context) throws BeansException {
        SpringContextManager.context = context;
        isInit.set(true);
    }
}
